package pl.oczadly.jabberclient.message.model;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManager;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.XMPPException;

import pl.oczadly.jabberclient.connection.ConnectionHolder;

public class MessageModel implements IMessageModel {

	private Chat chat;
	
	private String id;
	private String name;
	
	public MessageModel( String id, String name ) {
		this.id = id;
		this.name = name;
	}
	
	public void addChatManager( MessageListener messageListener ) {
		ChatManager chatManager = ConnectionHolder.getConnection().getChatManager();
		
		chat = chatManager.createChat( id, messageListener );
	}
	
	public void sendMessage( String message ) {
		try {
			chat.sendMessage( message );
		} catch( XMPPException e ) {
			e.printStackTrace();
		}
	}
	
	public void removeChatManager( MessageListener messageListener ) {
		chat.removeMessageListener( messageListener );
	}
	
}
